﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebshopPizzaRio
{
    public class Items : IFormattable
    {
        private String _pizzanaam;
        private Decimal _prijsperstuk;
        private int _aantal;
        private int _pizzaid;

        public Items()
        {

        }

        public Items(int pizzaid, String pizzanaam, Decimal prijsperstuk, int aantal)
        {
            _pizzaid = pizzaid;
            _pizzanaam = pizzanaam;
            _prijsperstuk = prijsperstuk;
            _aantal = aantal;
        }

        public String PizzaNaam
        {
            get { return _pizzanaam; }
            set { _pizzanaam = value; }
        }

        public int PizzaID
        {
            get { return _pizzaid; }
            set { _pizzaid = value; }
        }

        public Decimal PrijsperStuk
        {
            get { return _prijsperstuk; }
            set { _prijsperstuk = value; }
        }

        public int Aantal
        {
            get { return _aantal; }
            set { _aantal = value; }
        }

        public Decimal Totaal
        {
            get { return _prijsperstuk * _aantal; }
        }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            if (Object.ReferenceEquals(this, obj)) return true;
            if (this.GetType() != obj.GetType()) return false;

            Items objItem = (Items)obj;
            if (_pizzaid == objItem._pizzaid) return true;

            return false;
        }

        public override int GetHashCode()
        {
            return _pizzanaam.GetHashCode();
        }

        string System.IFormattable.ToString(string format, IFormatProvider formatProvider)
        {
        if (format == null) format = "G";

        if (formatProvider != null)
        {
            ICustomFormatter formatter = formatProvider.GetFormat(this.GetType()) as ICustomFormatter;

            if (formatter != null)
            return formatter.Format(format, this, formatProvider);
        }

        switch(format)
        {
        case "f" : return String.Format("{0}{1,10}{2,10}{3,20}",
        _pizzanaam,_aantal.ToString(),_prijsperstuk.ToString("c"),
        Totaal.ToString("c"));
        case "G" :
        default : return string.Format("{0}", _pizzanaam.ToString());
        }

        }

    }
}